<div align="center">

  <h1><code>EPC to EAN</code></h1>

  <strong>
    A webassembly library for batch conversion of EPCs to EANs written in Rust
    using <a href="https://rustwasm.github.io/docs/wasm-pack">wasm-pack</a> and
    the <a href="https://crates.io/crates/gs1">GS1 crate</a>.
  </strong>

</div>

## Usage

Because WebAssembly is meant to be loaded asynchronous, an extra step is necessary to use this library. Assuming a webpack environment that supports `import()`:

```js
// load the package
const loadGS1 = import('./gs1-wasm') // no global package yet

// gs1-wasm doesn't support arrays directly but instead takes a string of
// separated values. This makes the data handling much easier in WebAssembly.
// Any separator is allowed and there is no default.
const separator = ','
const epcList = [
  '3034F44BF043E6800000D970',
  '3034F44BF059A2800000E55C',
  '3034F457D8374EC000009B82'
].join(separator)

loadGS1.then((gs1) => {
  // batch_epc2ean takes a (stringified) list of EPCs and returns a
  // (stringified) list of EANs. Both are using the string given in the
  // second argument as separator
  const eans = gs1.batch_epc2ean(epcList, separator)
  console.log('converted', epcList, 'to', eans.split(','))
})
```

## Building

To build the package, `wasm-pack` is used. You also need to make sure that you have installed the _wasm32-unknown-unknown_ target.

```sh
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
```

Now building the package is done by `wasm-pack build`.
